<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="24">
            <a-form-item label="项目编号">
              <j-input placeholder="请输入项目编号" v-model="queryParam.xmbh"></j-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-item label="项目名称">
              <j-input placeholder="请输入项目名称" v-model="queryParam.xmmc"></j-input>
            </a-form-item>
          </a-col>
          <a-col :md="10" :sm="24">
            <a-form-item label="发布时间">
              <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" class="query-group-cust" v-model="queryParam.fbsj_begin"></j-date>
              <span class="query-group-split-cust"></span>
              <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" class="query-group-cust" v-model="queryParam.fbsj_end"></j-date>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-item label="结算单号">
              <j-input placeholder="请输入项目单号" v-model="queryParam.jsdh"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="3" :lg="7" :md="5" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <template slot="footer" slot-scope="currentPageData">
          <div v-show="hzShow">
            项目编号{{queryParam.xmbh}}，当前累计完成结算金额为{{zjeSum}}元，其中平台服务费为{{fwfSum}}元，灵工人员结算金额为{{jsjeSum}}元
          </div>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleDetail(record)">详情</a>
        </span>

      </a-table>
    </div>

    <cus-yjs-modal ref="modalForm" @ok="modalFormOk"></cus-yjs-modal>
  </a-card>
</template>

<script>

  import { getAction } from '@/api/manage'
  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import CusYjsModal from './modules/CusYjsModal'
  import JDate from '@/components/jeecg/JDate.vue'
  import JInput from '@/components/jeecg/JInput'

  export default {
    name: 'CusYjsList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      CusYjsModal,
      JDate,
      JInput
    },
    data () {
      return {
        description: '企业财务管理管理页面',
        form: this.$form.createForm(this),
        // 表头
        columns: [
          {
            title:'结算单号',
            align:"center",
            dataIndex: 'jsdh'
          },
          {
              title:'项目编号',
              align:"center",
              dataIndex: 'xmbh'
          },
          {
              title:'项目协议编号',
              align:"center",
              dataIndex: 'xmxybh'
          },
          {
              title:'项目名称',
              align:"center",
              dataIndex: 'xmmc'
          },
          {
              title:'发布时间',
              align:"center",
              dataIndex: 'fbsj'
          },
          {
            title:'结算金额',
            align:"center",
            dataIndex: 'jsje'
          },
          {
            title:'本次应付个税',
            align:"center",
            dataIndex: 'sigtaxje'
          },
          {
            title:'平台服务费',
            align:"center",
            dataIndex: 'fwfje'
          },
          {
            title:'总金额',
            align:"center",
            dataIndex: 'zje'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/project/lhygQyFinance/yjslist",
          edit: "/project/lhygQyFinance/edit",
          delete: "/project/lhygQyFinance/delete",
          deleteBatch: "/project/lhygQyFinance/deleteBatch",
          exportXlsUrl: "/project/lhygQyFinance/exportXls",
          importExcelUrl: "project/lhygQyFinance/importExcel",
        },
        dictOptions:{},
        queryParam: {
            xmbh: '',
            xmmc: '',
            fbsj_begin: '',
            fbsj_end: '',
            jsdh: '',
        } ,
        hzShow: false,
        zjeSum: '',
        fwfSum: '',
        jsjeSum: '',
      }
    },
    created() {
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      searchQuery(){
          if(!this.url.list){
              this.$message.error("请设置url.list属性!")
              return
          }
          //加载数据 若传入参数1则加载第一页的内容
          this.ipagination.current = 1;

          var params = this.getQueryParams();//查询条件
          this.loading = true;
          getAction(this.url.list, params).then((res) => {
              if (res.success) {
                  if(params.xmbh != "" && params.xmbh != undefined){
                      if(res.result.records != "" && res.result.records != undefined){
                          let z = 0;
                          let j = 0;
                          let f = 0
                          res.result.records.forEach((item,i) => {
                              z = (parseFloat(z) + parseFloat(item.zje)).toFixed(2);
                              j = (parseFloat(j) + parseFloat(item.jsje)).toFixed(2);
                              f = (parseFloat(f) + parseFloat(item.fwfje)).toFixed(2);
                          })
                          this.zjeSum = z;
                          this.jsjeSum = j;
                          this.fwfSum = f;
                          this.hzShow = true;
                      } else {
                          this.hzShow = false;
                      }
                  } else {
                      this.hzShow = false;
                  }
                  this.dataSource = res.result.records;
                  this.ipagination.total = res.result.total;
              }
              if(res.code===510){
                  this.$message.warning(res.message)
              }
              this.loading = false;
          })
      },
      searchReset(){
        this.hzShow = false;
        this.queryParam = {}
        this.loadData(1);
      }
    },
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>